package gocomm

import (
	"strings"
	"time"
)

const TIME_FORMAT = "2006-01-02 15:04:05"
const TIME_FORMAT_PECISE_MIN = "2006-01-02 15:04"

const TIME_FORMAT_AND = "2006-01-02+15:04:05"

func Date_UnixToTime(times int64) time.Time {
	return time.Unix(times, 0)
}
func Date_NanoToTime(times int64) time.Time {
	return time.Unix(0, times)
}
func Date_FormatDefault(t time.Time) string {
	return t.Format(TIME_FORMAT)
}

func Date_FormatDefaultAnd(t time.Time) string {
	return t.Format(TIME_FORMAT_AND)
}

func Date_Format(t time.Time, format string) string {
	return t.Format(format)
}

func Date_Parse(dateStr string) time.Time {
	t, _ := time.Parse(TIME_FORMAT, dateStr)
	return t
}

// 返回完整的年-月-日  yyyy-MM-dd 不会出现五月 = 5 情况=》 05
func GetYearMonthDayString(time *time.Time) string {
	nowStr := time.Format(TIME_FORMAT)
	YDd := strings.Split(nowStr, " ")[0] //获得年月日
	return YDd
}

// GetCurrTs return current timestamps
func GetCurrTs() int64 {
	return time.Now().Unix()
}
